import {G6GraphEvent, Graph, IEdge} from '@antv/g6';
import GraphEventName from '../consts/graph-event-name';
import StateType from '../consts/state-type';

export default function (graph: Graph) {
    graph.on('edge:mouseenter', (event: G6GraphEvent) => {
        event.item.toFront();
    });
    graph.on('edge:mousedown', (event: G6GraphEvent) => {
        const item = event.item as IEdge;

        if ((event.originalEvent as MouseEvent).ctrlKey) {
        } else {
            // graph.emit(GraphEventName.NODES_CLEAR_SELECT);
        }
        if (!item.hasState(StateType.SELECTED)) {
            item.setState(StateType.SELECTED, true);
            graph.emit(GraphEventName.ITEM_SELECTED,  item);
        }
    });
    graph.on('edge:mouseup', (event: G6GraphEvent) => {

        const item = event.item as IEdge;
        if ((event.originalEvent as MouseEvent).ctrlKey) {
        } else {
            graph.emit(GraphEventName.ITEMS_CLEAR_SELECT);
        }
        if (!item.hasState(StateType.SELECTED)) {
            item.setState(StateType.SELECTED, true);
            graph.emit(GraphEventName.ITEM_SELECTED,  item);
        }
    });
}
